package com.qf.io.fileCopy;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @Description:
 * @Author: xbb
 * @Date:2020/4/16
 */
public class fileCopyDemo {

    public static void main(String[] args) {
        String path = "C:\\Users\\xbb\\Pictures\\Camera Roll\\1.jpg";
        FileInputStream ips = null;
        FileOutputStream ops =  null;

        try {
            //读哪个文件
            ips = new FileInputStream(path);
            //往哪写
            ops = new FileOutputStream("C:\\Users\\xbb\\Desktop\\x.jpg");

            byte[] bytes = new byte[1024];
            int read = 0;

            while((read = ips.read(bytes,0,bytes.length))!=-1){
                ops.write(bytes,0,read);
            }


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(ips!=null){
                try {
                    ips.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(ops!=null){
                try {
                    ops.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
